package com.example.springfox.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringBootVersion;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * @author: hett
 * @date: 2022/1/17 10:13
 */
@Configuration
public class SwaggerConfig {
    @Value("${swagger.description}")
    private String description;
    @Value("${swagger.contactName}")
    private String contactName;
    @Value("${swagger.contactEmail}")
    private String contactEmail;
    @Value("${swagger.version}")
    private String version;
    @Value("${swagger.title}")
    private String title;

    @Bean
    Docket docket(){
        //选择版本3
        return new Docket(DocumentationType.OAS_30)
                //选择生成的接口文档
                .select()
//              //包所在的路径
                .apis(RequestHandlerSelectors.basePackage("com.example.springfox.controller"))
                //默认报下所有的接口都生成
                .paths(PathSelectors.any())
                .build()
                //接口文档初始化
                .apiInfo(apiInfo());
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .description(description)
                .contact(new Contact(contactName,null,contactEmail))
                .version("Swagger version "+version+", Spring Boot version "+ SpringBootVersion.getVersion())
                .title(title+"测试")
                .build();
    }

//    @Bean
//    public Docket adminDocket(){
//        //选择版本3
//        return new Docket(DocumentationType.OAS_30)
//                //选择生成的接口文档
//                .select()
////              //包所在的路径
//                .apis(RequestHandlerSelectors.basePackage("com.example.springfox.controller"))
//                //默认报下所有的接口都生成
//                .paths(PathSelectors.regex("admin.*"))
//                .build()
//                //接口文档初始化
//                .apiInfo(apiInfo());
//    }
}
